<?php
//error_reporting(0);
//ini_set('display_errors', '0');

require("library/MySQL.dll.php");
require_once 'library/common_function.php';
require_once 'library/app_config.php';

session_start();
if (isset($_GET['lang'])) {
    $_SESSION['lang'] = $_GET['lang'];
}
if (isset($_SESSION['lang'])) {
    if ($_SESSION['lang'] == 'vn')
        $hg = '_' . $_SESSION['lang'];
}

if (!isset($hg))
    $hg = "";

$db = new MySQL();

$sql_common = $db->select("select * from common");
$co_common = $db->fetch($sql_common);

$sql_home = $db->select("select * from home");
$co_home = $db->fetch($sql_home);

$sql_about = $db->select("select * from about");
$co_about = $db->fetch($sql_about);

$sql_product = $db->select("select * from product");
$co_product = $db->fetch($sql_product);

$sql_service = $db->select("select * from service");
$co_service = $db->fetch($sql_service);

$sql_news = $db->select("select * from news");
$co_news = $db->fetch($sql_news);

$sql_faq = $db->select("select * from faq");
$co_faq = $db->fetch($sql_faq);

$sql_tip = $db->select("select * from tip");
$co_tip = $db->fetch($sql_tip);

$sql_media = $db->select("select * from media");
$co_media = $db->fetch($sql_media);

$sql_contact = $db->select("select * from contact");
$co_contact = $db->fetch($sql_contact);

$sql_buywhere = $db->select("select * from buy_where");
$co_buy_where = $db->fetch($sql_buywhere);

$titlepage_pg = $co_common['titlepage' . $hg];
$metades_pg = $co_common['meta_des'];
$metakey_pg = $co_common['meta_key'];


$act = "home";
if (isset($_GET['act']))
    $act = $_GET['act'];


$homeClass = "";
$aboutClass = "";
$productClass = "";
$contactClass = "";
$linksClass = "";
$advertiseClass = "";
$newsClass = "";
$tipClass = "";

$siteweb = "siteleft";
if ($act == 'home') {
    $homeClass = 'active';

    if ($co_home['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_home['titlemenu' . $hg];
    if ($co_home['meta_des'] != "")
        $metades_pg = $co_home['meta_des'];
    if ($co_home['meta_key'] != "")
        $metakey_pg = $co_home['meta_key'];
}

elseif ($act == 'gioi-thieu' || $act == 'intro') {
    $aboutClass = 'active';
    $siteweb = "siteall";

    if ($co_about['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_about['titlemenu' . $hg];
    if ($co_about['meta_des'] != "")
        $metades_pg = $co_about['meta_des'];
    if ($co_about['meta_key'] != "")
        $metakey_pg = $co_about['meta_key'];
}

elseif ($act == 'product' || $act == "product-detail") {
    $productClass = 'active';
    $siteweb = "siteall";

    if ($co_product['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_product['titlemenu' . $hg];
    if ($co_product['meta_des'] != "")
        $metades_pg = $co_product['meta_des'];
    if ($co_product['meta_key'] != "")
        $metakey_pg = $co_product['meta_key'];
}

elseif ($act == 'dich-vu-khach-hang') {
    $serviceClass = 'cur';
    $siteweb = "siteall";

    if ($co_service['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_service['titlemenu' . $hg];
    if ($co_service['meta_des'] != "")
        $metades_pg = $co_service['meta_des'];
    if ($co_service['meta_key'] != "")
        $metakey_pg = $co_service['meta_key'];
}

elseif ($act == 'news' || $act == 'news-detail') {
    $newsClass = 'active';
    $siteweb = "siteall";

    if ($co_news['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_news['titlemenu' . $hg];
    if ($co_news['meta_des'] != "")
        $metades_pg = $co_news['meta_des'];
    if ($co_news['meta_key'] != "")
        $metakey_pg = $co_news['meta_key'];
}

elseif ($act == 'tip') {
    $tipClass = 'active';
    $siteweb = "siteall";

    if ($co_tip['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_tip['titlemenu' . $hg];
    if ($co_tip['meta_des'] != "")
        $metades_pg = $co_tip['meta_des'];
    if ($co_tip['meta_key'] != "")
        $metakey_pg = $co_tip['meta_key'];
}

elseif ($act == 'questions') {
    $faqClass = 'cur';
    $siteweb = "siteall";

    if ($co_faq['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_faq['titlemenu' . $hg];
    if ($co_faq['meta_des'] != "")
        $metades_pg = $co_faq['meta_des'];
    if ($co_faq['meta_key'] != "")
        $metakey_pg = $co_faq['meta_key'];
}


elseif ($act == 'media') {
    $mediaClass = 'cur';
    $siteweb = "siteall";

    if ($co_media['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_media['titlemenu' . $hg];
    if ($co_media['meta_des'] != "")
        $metades_pg = $co_media['meta_des'];
    if ($co_media['meta_key'] != "")
        $metakey_pg = $co_media['meta_key'];
}

elseif ($act == 'contact') {
    $contactClass = 'active';
    $siteweb = "siteall";

    if ($co_contact['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_contact['titlemenu' . $hg];
    if ($co_contact['meta_des'] != "")
        $metades_pg = $co_contact['meta_des'];
    if ($co_contact['meta_key'] != "")
        $metakey_pg = $co_contact['meta_key'];
}

elseif ($act == 'buy_where') {
    $whereClass = 'active';
    $siteweb = "siteall";

    if ($co_buy_where['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_buy_where['titlemenu' . $hg];
    if ($co_buy_where['meta_des'] != "")
        $metades_pg = $co_buy_where['meta_des'];
    if ($co_buy_where['meta_key'] != "")
        $metakey_pg = $co_buy_where['meta_key'];
}

elseif ($act == 'ho-tro') {
    $supportClass = 'cur';
    $siteweb = "siteall";

    if ($co_support['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_support['titlemenu' . $hg];
    if ($co_support['meta_des'] != "")
        $metades_pg = $co_support['meta_des'];
    if ($co_support['meta_key'] != "")
        $metakey_pg = $co_support['meta_key'];
}
elseif ($act == 'buy-where') {
    $buywhereClass = 'active';
    $siteweb = "siteall";

    if ($co_support['titlemenu' . $hg] != "")
        $titlepage_pg .= " - " . $co_buywhere['titlemenu' . $hg];
    if ($co_support['meta_des'] != "")
        $metades_pg = $co_buywhere['meta_des'];
    if ($co_support['meta_key'] != "")
        $metakey_pg = $co_buywhere['meta_key'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title><?= $titlepage_pg ?></title>
        <META NAME= "description" content="<?= $metades_pg ?>" />
        <META NAME="keywords" CONTENT="<?= $metakey_pg ?>" />	
        <link href="<?= APPLICATION_URL ?>favicon.ico" rel="shortcut icon">
        <?php require 'inc/css.php'; ?>
		<script>
			var lang = "<?php echo isset($_SESSION['lang']) ? $_SESSION['lang'] : 'vn'; ?>";
			var baseUrl = "<?php echo APPLICATION_URL; ?>";
		</script>
		<!--[if lt IE 9]>
		<script src="<?php echo APPLICATION_URL; ?>js/html5.js"></script>
		<script src="<?php echo APPLICATION_URL; ?>js/selectivizr-min.js"></script>
		<script src="<?php echo APPLICATION_URL; ?>js/respond.min.js"></script>	
		<![endif]-->
    </head>
    <body>
        <?php require_once 'header.php'; ?>
        <div class="main-ctn <?php if ($act == 'home') echo 'mt30' ?>">
            <?php include_once $act . '.php'; ?>
        </div>	
        <div class="clear"></div>
        <div class="footer">
            <div class="footer-ctn">
                <a href="<?= $co_common['facebook'] ?>"><img class="fb" src="<?= APPLICATION_URL ?>images/facebook.png" /></a>
                <span class="copyright">|  <?= $co_common['copyright'.$hg] ?></span>
                <div class="ltc">
                    <?php
                    $ip = $_SERVER['REMOTE_ADDR'];
                    if (isset($_SESSION['clientIP']) && $_SESSION['clientIP'] == $ip) {
                        
                    } else {
                        $db = new MySQL();
                        //cap nhat du lieu
                        $query = "update counting set count = count + 1";
                        $query.=" where id=1";
                        $sql = $db->update($query);
                        $_SESSION['clientIP'] = $ip;
                    }

                    $sql_count = $db->select("select * from counting where id = 1");
                    $count_common = $db->fetch($sql_count);
                    $count = intval($count_common['count']);
                    
                    $arr_num = array();
                    while ($count > 0) {
                        $num = $count % 10;
                        $count = intval($count / 10);
                        array_push($arr_num, $num);
                    }
                    __('Lượt truy cập');
                    $db->close();
                    ?>
                </div>
                <?php
                while (!empty($arr_num)):?>
                <div class="ltc-num"><?= array_pop($arr_num); ?></div>
                <?php endwhile; ?>

                <img class="rau" src="<?= APPLICATION_URL ?>images/rau.png" alt=""/>
            </div>
        </div>
        <?php require 'inc/js.php'; ?>
    </body>
</html>
<script>
</script>